<?php
namespace api\user\validate;

use think\Validate;

class ChangePasswordValidate extends Validate
{
    protected $rule = [
            'password'   => 'require',
            'confirm_password'   => 'require|confirm:password',
            // 'verification_code' => 'require|checkVerificationCode'
    ];
    protected $message = [
            'password.require'   => '请输入您的新密码',
            'confirm_password.require'   => '请确认新密码',
            'confirm_password.confirm'  => '两次密码不一致',
            // 'verification_code.require' => '请输入验证码'
    ];

    protected $scene = [
    ];

    protected function checkPassword($value, $rule, $data)
    {
       if ((preg_match('/^[a-zA-Z]{1}[a-zA-Z0-9]{7}$/i', $value))&&(preg_match('/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]+$/', $value))){
            return true;
        }else{
            return '密码格式不正确';
        }
    }

    protected function checkVerificationCode($value, $rule, $data)
    {
        if (preg_match('/^\d{6}$/', $value)){
            return true;
        }else{
            return '验证码格式不正确';
        }
    }
}